<template>
	<div style="width: 100%;height: 100%">
		<title-common style="margin-bottom: 10px" v-if="config.showTitle" :config="config"></title-common>
		<!--超链接-->
		<div v-if="config.advancedConf.openLink" @mouseenter="show=true" @mouseleave="show=false" :style="{'font-size':config.dataSources.fontSize+'px','color':!show?config.dataSources.titleColor:config.advancedConf.textColor,'text-align':config.dataSources.textAlign,'font-weight':config.dataSources.fontWeight}">
			<span style="cursor: pointer" @click="onClick" :style="getStyle(config.dataSources)" target="_blank">{{content}}</span>
		</div>
		<div v-else :style="{'font-size':config.dataSources.fontSize+'px','color':config.dataSources.titleColor,'text-align':config.dataSources.textAlign,'font-weight':config.dataSources.fontWeight}">
			<span :style="getStyle(config.dataSources)">{{content}}</span>
		</div>
	</div>
</template>

<script>
/**
 * 文本组件
 */
import ComponentView from "@/views/modules/preview/components/common/component-view.js";
import ScreenViewManageApi from "@/api/screen/core/screen-view-manage.js";
export default {
	name: "text-view",
	mixins:[ComponentView],
	data() {
		return {
			content:"",
			show:false,
			params:{}
		}
	},
	methods: {
		getData(){
			let dataSources=this.config.dataSources;
			//是否为动态文本
			if(dataSources.source=='dynamic' && this.config.dataSources.dataModel && this.config.dataSources.measures && this.config.dataSources.measures.length>0){
				let obj = {
					dataModel: this.config.dataSources.dataModel,
					measures:this.config.dataSources.measures,
					dimensions: [],
					colorLegends: [],
					params: this.params,
					filterParams: [],
					resultNum:this.config.dataSources.resultNum
				}
				let self = this;
				//获取数据
				ScreenViewManageApi.getData(JSON.stringify(obj)).then(res => {
					if( res && res.data && res.data.length>0){
						self.data = res.data;
						this.gestalt(self.data[0])
						//数据进行格式化
						self.content=this.formatTemplateField(dataSources.content,self.data[0])||dataSources.content;
					}else {
						self.content=dataSources.content;
					}
				});
			}else {
				this.content=dataSources.content;
			}
		},
		//点击事件
		onClick(){
			let mode=this.config.advancedConf.linkMode;
			let url=this.config.advancedConf.linkUrl;
			if(!url){
				return;
			}
			let target="_blank";
			//当前页面打开
			if(mode && mode=='curPage'){
				target="_self";
			}
			//不以http与https开头
			if(!url.startsWith('http') && !url.startsWith('https')){
				if(!url.startsWith('/')){
					url="/"+url;
				}
				url="/screen" + url;
			}
			window.open(url,target);
		},
		getStyle(dataSources){
			if(!dataSources.neonLightShow){
				return
			}else {
				return 'text-shadow:0 0 7px '+dataSources.neonLightColor+',0 0 10px '+dataSources.neonLightColor+',0 0 21px '+dataSources.neonLightColor+',' + '0 0 42px #fff'+ ',0 0 82px #fff'  +',0 0 92px #fff'
			}

		}
	},
	watch: {}
}
</script>

<style scoped>
</style>
